import Admin from '../modules/admin.js';
import Users from '../modules/users/users.js';
import Films from '../modules/films/films.js';
import Manage from '../modules/manage.js';
import Cinemas from '../modules/cinemas/cinemas.js';
import Theater from '../modules/theater/theater.js';
import ComingSoon from "../modules/comingSoon/comingSoon.js"
import HitMovies from "../modules/hitMovies/hitMovies.js"
import Hotbroadcast from "../modules/hotBroadcast/hotBroadcast.js"

let routes = {
    '/admin': () => new Admin(),
    '/manage': {
        on: (next) => new Manage(next),
        '/users': () => new Users(),
        '/films': () => new Films(),
        '/cinemas': () => new Cinemas(),
        '/theater': () => new Theater(),
        '/comingSoon': () => new ComingSoon(),
        '/hitMovies': () => new HitMovies(),
        '/hotBroadcast': () => new Hotbroadcast(),

    },
};

const $ = layui.$;
// 每次ajax请求都会将token信息从localStorage中取出并设置到请求头中
$.ajaxSettings.beforeSend = function (xhr, request) {
    // 在这里加上你的 token 
    xhr.setRequestHeader('Authorization', 'Bearer ' + layui.data('tokens').token);
}
// 默认访问登录模块
location.hash = location.hash || '#admin'
let router = Router(routes).configure({
    recurse: 'forward', // backward 从右往左
    async: true, // 需要手动控制后续模块的渲染
    strict: false // 路径允许以"/"结尾（也可以是其他自定义的分隔符） // true 不允许
}); // 实例化路由
router.init(); // 初始化路由